package utilidades;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;


/** Clase render que cambia la visualización de la tabla, agregando colores.
 * @author kevincifuentes
 *
 */
public class MiRender extends DefaultTableCellRenderer {



	/* (non-Javadoc)
	 * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
	 */
	public Component getTableCellRendererComponent(JTable table,
			Object value, boolean isSelected, boolean hasFocus, int row,
			int column) 
	{
		JLabel cell = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,column);          
		if((row ==0) || (column == 0)){
			cell.setFont(new Font("Serief",Font.BOLD|Font.ITALIC,14));
			cell.setHorizontalAlignment(CENTER);
			cell.setForeground(Color.WHITE);
			cell.setBackground(Color.gray);
		}

		else{
			cell.setForeground(Color.BLACK);
			cell.setHorizontalAlignment(CENTER);

			if(column == 5 && row !=0)
			{
				String str =(String) table.getValueAt(row, column);
				str=str.substring(0, str.length()-2);
				Double valor = Double.parseDouble(str);
				if(valor >= 0)
				{
					cell.setBackground(Color.GREEN);
					//cell.setHorizontalAlignment(CENTER);
				}else{
					cell.setBackground(Color.RED);
					//cell.setHorizontalAlignment(CENTER);
				}
			}else{

				cell.setBackground(Color.WHITE);
				//cell.setHorizontalAlignment(CENTER);
			}
		}
		return cell;
	}
}
